<?php

namespace App\Http\Resources\panyuan;

use App\model\Workshop;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Support\Carbon;

class WorkshopOverdueCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'code'=>'success',
            'data'=> $this->collection->map(function($item){

                if($item->workshop->type==0){
                    $price=$item->workshop->rent!=0 ? $item->workshop->rent.Workshop::RENT  : '面议';
                }else{
                    $price=$item->workshop->price!=0 ? $item->workshop->rent.Workshop::SALE  : '面议';
                }
                return [
                    'workshop_id'=>$item->workshop->id,
                    'logo'=>$item->workshop->logo.Workshop::LOGO,
                    'title'=>$item->workshop->title,
                    'area'=>$item->workshop->area,
                    'price'=>$price,
                    'tags'=>$item->workshop->tags->reject(function($item,$key){
                        return $key>2;
                    }),
                    'is_updated'=>$item->is_updated,
                    'is_shenhe'=>$item->is_shenhe,
                    'overdue_time'=>Carbon::parse($item->overdue_time)->format("Y-m-d"),
                    'shenhe'=>$item->workshop->shenhe,
                    'times'=>substr($item->updated_at,0,10),
                    'code'=>$item->code,
                    'id'=>$item->id,
                ];

            })
        ];
    }
}
